<?php

namespace app\common\model;

use think\Cache;
use think\Model;


class DishUser extends Model{



    // 表名
    protected $name = 'mt_dish_user';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;




    public function saveUser($in_uname,$in_phone,$es_id,$type = 1){
        $where = array();
        $where['mdu_enterprise_id'] = $es_id;
        $where['mdu_name'] = $in_uname; //1客户2供货商
        $where['mdu_type'] = $type; //1客户2供货商
        $user = self::where($where)->find();
        if ($user){
            if($in_phone == $user['mdu_phone']){
                $m_uid = $user['mdu_id'];
            }else{
                //为了系统能看到这里要做个假删除
                $user_update['mdu_phone'] = $in_phone;
                $user->save($user_update);
                $m_uid = $user['mdu_id'];
            }
        }else{
            $set = array(
                'mdu_m_id' => $es_id,
                'mdu_name' => $in_uname,
                'mdu_phone' => $in_phone,
                'mdu_type' => 1, //出库对应客户
                'mdu_sort' => 1,
                'mdu_create_time' => time(),
                'mdu_update_time' => time(),
                'mdu_enterprise_id' => $es_id
            );
            $res = self::insertGetId($set);
            $m_uid = $res;
            if (!$res){
               return false;
            }
        }
        return $m_uid;
    }



}